<?php

//define url
defined('DOMAIN') || define('DOMAIN', 'http://' . $_SERVER['HTTP_HOST']);
defined('ADMIN_URL') || define('ADMIN_URL', DOMAIN . 'admincp/');
defined('UPLOAD_URL') || define('UPLOAD_URL', DOMAIN . 'uploads/');
defined('JS_URL') || define('JS_URL', DOMAIN . 'js/');
defined('CSS_URL') || define('CSS_URL', DOMAIN . 'css/');
defined('IMG_URL') || define('IMG_URL', DOMAIN . 'images/');
//define directory
defined('BASE_DIR') || define('BASE_DIR', realpath(dirname(__FILE__)));
defined('MODULE_DIR') || define('MODULE_DIR', BASE_DIR . '/modules/');
defined('MODEL_DIR') || define('MODEL_DIR', BASE_DIR . '/models/');
defined('INCLUDE_DIR') || define('INCLUDE_DIR', BASE_DIR . '/includes/');
defined('LIBRARY_DIR') || define('LIBRARY_DIR', BASE_DIR . '/library/');
defined('UPLOAD_DIR') || define('UPLOAD_DIR', BASE_DIR . '/uploads/');

defined('NUM_ROW_PER_PAGE') || define('NUM_ROW_PER_PAGE', 6);
defined('MEMBER_IMG_UPLOAD_PATH') || define('MEMBER_IMG_UPLOAD_PATH', '/uploads/images/');
defined('CARD_TEMP_UPLOAD_PATH') || define('CARD_TEMP_UPLOAD_PATH', '/uploads/ecard/temp/');

$config['title'] = 'Những người bạn không bao giờ lãng quên';
$config['description'] = 'Bạn cùng quê, những người bạn không bao giờ lãng quên.';
$config['keyword'] = 'Bạn cùng quê, những người bạn không bao giờ lãng quên.';

include LIBRARY_DIR . "/common.php";
$common = new common();
include_once MODEL_DIR . 'member.class.php';
$member = new member();

//database connection
//include (LIBRARY_DIR . "mysql.php"); //database object
//$db = new database();

$db_host = "localhost";  // server name
$db_user = "root";       // user name
$db_pass = "root";           // password
$db_dbname = "cungque";           // database name
$db_charset = "utf8";           // optional character set (i.e. utf8)
// Make sure you include the class
include(LIBRARY_DIR . "mysql.class.php");

// We will pass in our connection information but please note that
// this information can be set aurtomatically for you in the header
// of the mysql.class.php file and these parameters are all optional.
// See the top section of the mysql.class.php file for more info.
$db = new MySQL(true, $db_dbname, $db_host,$db_user,$db_pass,$db_charset);

// This checks for errors and if there is one, terminates the script
// while showing the last MySQL error.
if ($db->Error())
    $db->Kill();


function clean_html_output($buffer) {
    global $config;
//    $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer); // remove comments
//    $buffer = str_replace(array("\r\n", "\r", "\n", "\t","  "), '', $buffer); // remove tabs, spaces, newlines, etc.
//    $buffer = str_replace('{ ', '{', $buffer); // remove unnecessary spaces.
//    $buffer = str_replace(' }', '}', $buffer);
//    $buffer = str_replace('; ', ';', $buffer);
//    $buffer = str_replace(', ', ',', $buffer);
//    $buffer = str_replace(' {', '{', $buffer);
//    $buffer = str_replace('} ', '}', $buffer);
//    $buffer = str_replace(': ', ':', $buffer);
//    $buffer = str_replace(' ,', ',', $buffer);
//    $buffer = str_replace(' ;', ';', $buffer);

    if ($_SESSION['mem']['fullname']) {
        $titleName = $_SESSION['mem']['fullname'];
    } elseif ($_SESSION['client']['fullname']) {
        $titleName = $_SESSION['client']['fullname'];
    }
    if ($titleName) {
        $config['title'] = $titleName . ' - ' . $config['title'];
    }

    $buffer = str_replace("[TITLE]", $config['title'], $buffer);
    $buffer = str_replace("[KEYWORD]", $config['keyword'], $buffer);
    $buffer = str_replace("[DESCRIPTION]", $config['description'], $buffer);

    return $buffer;

    return $buffer;
}

if (!function_exists('json_decode')) {

    function json_decode($content, $assoc=false) {
        include (LIBRARY_DIR . "json.php");
        if ($assoc) {
            $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
        } else {
            $json = new Services_JSON;
        }
        return $json->decode($content);
    }

}

if (!function_exists('json_encode')) {

    function json_encode($content) {
        include (LIBRARY_DIR . "json.php");
        $json = new Services_JSON;
        return $json->encode($content);
    }

}
?>
